home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / ftp / RCS / getpass.c,v < prev    next >
Encoding:
Text File  |  1990-10-27  |  2.1 KB  |  127 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    shirriff:1.3; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     90.04.12.17.40.43;  author douglis;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     89.07.26.23.49.05;  author rab;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     89.07.26.23.46.35;  author rab;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 1.3
  30. log
  31. @ifdef'ed out open of /dev/tty for sprite.
  32. @
  33. text
  34. @/*
  35.  * Copyright (c) 1985 Regents of the University of California.
  36.  * All rights reserved.
  37.  *
  38.  * Redistribution and use in source and binary forms are permitted
  39.  * provided that this notice is preserved and that due credit is given
  40.  * to the University of California at Berkeley. The name of the University
  41.  * may not be used to endorse or promote products derived from this
  42.  * software without specific prior written permission. This software
  43.  * is provided ``as is'' without express or implied warranty.
  44.  */
  45.  
  46. #ifndef lint
  47. static char sccsid[] = "@@(#)getpass.c    5.5 (Berkeley) 3/14/88";
  48. #endif /* not lint */
  49.  
  50. #include <stdio.h>
  51. #include <signal.h>
  52. #include <sgtty.h>
  53.  
  54. #include "ftp_var.h"
  55.  
  56. static    struct sgttyb ttyb;
  57. static    int flags;
  58. static    FILE *fi;
  59.  
  60. static intfix()
  61. {
  62.     ttyb.sg_flags = flags;
  63.     if (fi != NULL)
  64.         (void) stty(fileno(fi), &ttyb);
  65.     exit(SIGINT);
  66. }
  67.  
  68. char *
  69. mygetpass(prompt)
  70. char *prompt;
  71. {
  72.     register char *p;
  73.     register c;
  74.     static char pbuf[50+1];
  75.     int (*sig)();
  76.  
  77. #ifndef sprite
  78.     if ((fi = fopen("/dev/tty", "r")) == NULL)
  79.         fi = stdin;
  80.     else
  81.         setbuf(fi, (char *)NULL);
  82. #else /* sprite */
  83.     fi = stdin;
  84. #endif /* sprite */
  85.     
  86.     sig = signal(SIGINT, intfix);
  87.     (void) gtty(fileno(fi), &ttyb);
  88.     flags = ttyb.sg_flags;
  89.     ttyb.sg_flags &= ~ECHO;
  90.     (void) stty(fileno(fi), &ttyb);
  91.     fprintf(stderr, "%s", prompt); (void) fflush(stderr);
  92.     for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) {
  93.         if (p < &pbuf[sizeof(pbuf)-1])
  94.             *p++ = c;
  95.     }
  96.     *p = '\0';
  97.     fprintf(stderr, "\n"); (void) fflush(stderr);
  98.     ttyb.sg_flags = flags;
  99.     (void) stty(fileno(fi), &ttyb);
  100.     (void) signal(SIGINT, sig);
  101.     if (fi != stdin)
  102.         (void) fclose(fi);
  103.     return(pbuf);
  104. }
  105. @
  106.  
  107.  
  108. 1.2
  109. log
  110. @
  111. @
  112. text
  113. @d44 1
  114. d49 4
  115. @
  116.  
  117.  
  118. 1.1
  119. log
  120. @Initial revision
  121. @
  122. text
  123. @d21 2
  124. a41 1
  125.     int (*signal())();
  126. @
  127.